<template>
  <div class="comment-reply">
    <!-- 头部 -->
    <van-nav-bar :title="comment.reply_count>0?`${comment.reply_count}条回复`:'暂无回复'">
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>

    <div class="scroll-wrap">
        <!-- 评论数据 -->
        <comment-item :comment="comment"/>
        <!-- 回复列表 -->
        <!-- 1.标题部分 -->
        <van-cell  title="全部回复" />
        <!-- 2.列表部分 -->
        <comment-list :list="commentList" :source="comment.com_id" type="c"/>
    </div>
   
    <!-- 添加回复按钮区域 -->
    <div class="post-wrap">
        <van-button type="danger" size="small" class="reply-btn" round @click="isPostShow=true">添加回复</van-button>
    </div>

    <!--  添加回复弹出框 -->
    <van-popup v-model="isPostShow" position="bottom">
        <comment-post :target="comment.com_id" @post-success="onPostSuccess"/>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item'
import CommentList from './comment-list'
import CommentPost from './comment-post'

export default {
  name: 'CommentReply',
  components:{
      'comment-item':CommentItem,
      'comment-list':CommentList,
      'comment-post':CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
        isPostShow:false,
        commentList:[]
    }
  },
  methods: {
      onPostSuccess(data){
        // console.log(data);
        // 1.更新回复数量
        this.comment.reply_count++
        // 2.关闭弹层
        this.isPostShow = false
        // 3.添加数据到顶部
        this.commentList.unshift(data.new_obj)
      }
  },
  created() {},
}
</script>

<style lang="less" scoped>
.scroll-wrap{
    position: fixed;
    top: 92px;
    bottom: 88px;
    width: 100%;
    overflow-y: auto;
   
}
.post-wrap{
    position: fixed;
    bottom:0;
    left:0;
    right: 0;
    height:88px;
    border-top:1px solid #d8d8d8;
    display: flex;
    justify-content: center;
    align-items: center;
    .reply-btn{
        width: 60%;

    }
}
</style>